public class ListNode1 {
    int val;
    String name;
    ListNode1 next;
    public ListNode1(String name){
        this.name = name;
    }

    public static void traverse(ListNode1 head){
        for(ListNode1 p = head;p != null; p = p.next){
            System.out.println(p.val);
        }
    }

    public static void traverserec(ListNode1 head){
        if(head != null){
            System.out.println(head.val);
            traverserec(head.next);
        }
    }

    public static void main(String[] args) {
        ListNode1 node1 = new ListNode1("node1");
        ListNode1 node2 = new ListNode1("node2");
        ListNode1 node3 = new ListNode1("node3");
        node1.val = 1;
        node1.next = node2;
        node2.next = node3;
        node2.val = 2;
        node3.val = 3;

        traverse(node1);

        System.out.println(" ============rec data ========");
        traverserec(node1);
    }
}
